﻿using Anay.Data.DataEntity;
using System;
using System.Collections.Generic;
using Anay.TaskScheduling.JobConfig;

namespace Anay.TaskScheduling.Common
{
    public class ConfigDBHelper: IConfigHelper
    {


        private OracleDataEntityDAL<Ep_task_config> dAL = new OracleDataEntityDAL<Ep_task_config>("TaskScheduing");

        public void AddConfig(Ep_task_config task_Config)
        {
            throw new NotImplementedException();
        }

        public bool DeleteConfig(string id)
        {
            throw new NotImplementedException();
        }

        public List<Ep_task_config> GetAllList()
        {
            return dAL.List(new Ep_task_config());
        }

        public DateTime? GetLastRunTime(string id)
        {
            var Task_Config = GetTask_config(id);
            return (DateTime)Task_Config.LastRunTime ;
        }

        //获取启用的全部

        public List<Ep_task_config> GetTaskConfigList(bool IsEnabled = true)
        {

            if (!IsEnabled)
                return dAL.List(new Ep_task_config() { IsDelete = "1" });

            return dAL.List(new Ep_task_config() { IsEnabled = "0", IsDelete = "1" });
        }

        //获取个人

        public Ep_task_config GetTask_config(string id)
        {
            return dAL.Load(id);
        }


        public Ep_task_config GetTask_ConfigByJobName(string name)
        {
            var list = dAL.List(new Ep_task_config() { JobName = name });
            if (list.Count > 0)
            {
                return list[0];
            }
            else
            {
                return null;
            }
        }

        public void RefreshConfigs()
        {
            throw new NotImplementedException();
        }

        public void UpdateConfig()
        {
            throw new NotImplementedException();
        }


        //修改最后运行时间

        public bool UpdateLastRunTime(Ep_task_config task_Config)
        {

            task_Config.LastRunTime = DateTime.Now;
            return dAL.Update(task_Config) > 0;
        }
        public bool UpdateTime(Ep_task_config task_Config)
        {

            task_Config.UpdateDate = DateTime.Now;
            return dAL.Update(task_Config) > 0;
        }

    }
}
